Skip to content

Letterbox chef-supplied thumbnails to 400×225 PNG - #888

Merged
rtibbles merged 1 commit into
learningequality:mainfrom
rtibblesbot:issue-882-54ce35
Nov 18, 2026
Merged

rtibbles merged 1 commit into
learningequality:mainfrom
rtibblesbot:issue-882-54ce35

Conversation

@rtibblesbot

@rtibblesbot rtibblesbot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Studio now stores every thumbnail as a 400×225 PNG and converts at publish only for older ricecooker versions.

  • ThumbnailFile and Base64ImageFile scale down to fit, centre on a transparent 400×225 canvas and upload as PNG.
  • ImageConversionHandler takes generic width/height/maintain_aspect_ratio context; THUMBNAIL_RESIZE passes 400×225 with letterboxing.
  • Sources are EXIF-rotated and converted to sRGB from an embedded ICC profile before scaling.
  • _ExerciseBase64ImageFile no longer inherits from Base64ImageFile, so exercise images stay unconverted.
  • SVG thumbnails now fail processing: no thumbnail preset accepts SVG.
  • TiledThumbnailFile tiles the unconverted chef images, not the letterboxed ones.

References

Closes #882. Studio counterpart: learningequality/studio#6351.

Reviewer guidance

Suggested review: Full code review, then manual QA once the reviewer sets Needs QA.

  • Confirm the calls studio#6351 leaves open: letterboxing channel thumbnails, applying EXIF orientation, converting ICC profiles to sRGB, and rejecting SVG thumbnails.
  • Confirm extracted PDF/EPUB thumbnails may stay off-size (not 400×225) once Studio stops converting at publish for ricecooker 0.9.0+.
  • Upload a chef with landscape, portrait, small and transparent thumbnails and check the letterboxing on Studio and Kolibri cards.

Unit tests on CI cover landscape, portrait, smaller-than-target, transparent, 16-bit grayscale and EXIF-rotated sources.

AI usage

Used Claude Code to plan and implement the conversion and its tests. Verified with the full test suite and prek.


Written by rtibblesbot, an LLM-based coding agent.

@rtibblesbot

🟡 Waiting for feedback

WAITING · on a reviewer
Last updated: 2026-11-07 03:47 UTC

@rtibblesbot
rtibblesbot marked this pull request as ready for review November 4, 2026 03:21
@rtibblesbot
rtibblesbot requested review from a team and leq-bot November 4, 2026 03:21

@rtibbles rtibbles left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a little too specific in terms of the utility - better to make it slightly more general and have a thumbnail specific preset configuration to pass around.

Comment thread ricecooker/utils/pipeline/convert.py Outdated


class ImageConversionContextMetadata(ContextMetadata):
thumbnail: bool = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like it would be simpler for this just to be width and height properties here? We can then have a constant that encodes the thumbnail dimensions that gets passed around, and this just becomes a generic resize utility.

maintain_aspect_ratio as a boolean is then used to determine whether to letterbox or not - if both are given, and it's set, we apply letterboxing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in the amended commit:

  • resize_image(image, width, height, maintain_aspect_ratio) in utils/images.py replaces letterbox_thumbnail: letterboxes when both dimensions are given and maintain_aspect_ratio is set, scales proportionally when one is given, stretches when it is unset.
  • ImageConversionContextMetadata now carries width/height/maintain_aspect_ratio; cache key suffix is :{w}x{h}:fit|stretch.
  • THUMBNAIL_RESIZE constant in utils/images.py is the thumbnail preset; ThumbnailFile and Base64ImageFile pass it as pipeline context.
  • Searched for every thumbnail context flag use: 2 File classes, 5 test call sites — all switched to THUMBNAIL_RESIZE.
  • Added tests for the stretch and single-dimension paths.

- ImageConversionHandler gains a `thumbnail` context flag: scale down to fit, centre on a transparent 400×225 RGBA canvas (matches learningequality/studio#6351)
- ThumbnailFile and Base64ImageFile set the flag; exercise and extracted thumbnails are unchanged
- TiledThumbnailFile tiles the unconverted sources

Closes learningequality#882

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rtibbles rtibbles self-assigned this Nov 17, 2026
@rtibbles
rtibbles merged commit 654b826 into learningequality:main Nov 18, 2026
55 checks passed

Copy link
Copy Markdown
Contributor Author

Quick check on rtibblesbot's work on this PR: react 👍 helpful · 😕 mixed · 👎 not helpful. Reply with anything specific.

@rtibblesbot
rtibblesbot deleted the issue-882-54ce35 branch November 18, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert chef-supplied thumbnails to 400×225 PNG before upload

2 participants